#!/bin/sh
# auf strut.io editieren, Präsentieren, Publishen, Strg-S zum Saven, dann das regex Script drüber laufen lassen.

Title="SecuLution Feature"
Description="SecuLution product features"
Author="SecuLution GmbH"
page=features_en
page_files="$page"_files
filename=$page.htm
backup=$filename.bak
tmpfilename=$filename.tmp
home="home_en.htm"
home_de="home.htm"

if grep -q '<!-- processed -->' $filename; then
	if test -e $backup; then
		echo $0 using backup $backup
		cp $backup $filename
	else
		echo Backup $backup existiert nicht
		exit 1
	fi
else
	. ./createbackup.sh
fi

ersetzen() {
	nummer=`cat $filename| grep -ni $tag|cut -d ':' -f1`
	nummer=`expr $nummer - $davor`
	weiter=`expr $nummer + $anzahl`
	gesamt=`wc -l $filename|cut -d' ' -f1`
	cat $filename | sed -n "1,$nummer p" > $tmpfilename
	echo -n $einsetzen >> $tmpfilename
	cat $filename| sed -n "$weiter,$gesamt p" >> $tmpfilename
	rm $filename
	mv $tmpfilename $filename
}

loeschen() {
	cat $filename | grep -v "$tag" > $tmpfilename
	rm $filename
	mv $tmpfilename $filename
}

#  Als erstes den Google Analytics Block entfernen.
start=1
tag=googleanaly
anzahl=10
davor=2
einsetzen=""
ersetzen

mv $filename $tmpfilename
# Jetzt die Links anpassen
cat $tmpfilename | \
	sed -f sed-command-files/remove-google-analytics.sed |\
	sed "s@</head>@<script async=\"\" src=\"./support_files/controlyoutube.js\"></script></head>@" | \
	sed "s/Deck Title/$Title/" | \
	sed 's/^<!.*-->$//' | \
	sed "s/\"description\" content=\"TODO\"/\"description\" content=\"$Description\"/" | \
	sed "s/\"author\" content=\"TODO\"/\"author\" content=\"SecuLution GmbH\"/" | \
	sed "s@http://strut.io/editor/preview_export/css/themes/default-reset.css@./CSS/default-reset.css@" | \
	sed "s@http://strut.io/editor/preview_export/reveal/css/theme/default.css@./CSS/default.css@" | \
	sed "s@./${page}_files/aw.htm@http://www.seculution.de/versions/aw.txt@" | \
	sed "s@./${page}_files/agent.htm@http://www.seculution.de/versions/agent.txt@" | \
	sed "s@./${page}_files/server.htm@http://www.seculution.de/versions/server.txt@" | \
	sed "s@./${page}_files/uninstaller.htm@http://www.seculution.de/versions/uninstaller.txt@" | \
	sed "s@<div id=\"overview\" class=\"step future\" .*<\/div>@@" | \
	sed "s/http:\/\/www.4ss.de\/relative//g" | \
	sed "s/http:\/\/www.4ss.de\/$filename//g" | \
	sed "s/http:\/\/www.4ss.de/./" | \
	sed "s/http:\/\/www.echte-sicherheit.de\/relative//g" | \
	sed "s/http:\/\/www.echte-sicherheit.de\/$filename//g" | \
	sed "s/http:\/\/www.echte-sicherheit.de/./" | \
	sed "s/<img src=\".\/${page}_files\/right.png\">/<a href=\"javascript:impress().next();\"><img src=\".\/${page}_files\/right.png\"><\/a>/" | \
	sed "s/<img src=\".\/${page}_files\/_right.png\">/<a href=\"javascript:impress().next();\"><img src=\".\/${page}_files\/_right.png\"><\/a>/" | \
	sed "s/<img src=\".\/${page}_files\/sl400x420.png\">/<a href=\".\/$home#\/step-5\"> <img src=\".\/${page}_files\/sl400x420.png\"><\/a>/g" | \
	sed "s/<img src=\".\/${page}_files\/sl80x85.png\">/<a href=\".\/$home#\/step-5\"> <img src=\".\/${page}_files\/sl80x85.png\"><\/a>/g" | \
	sed 's/<font color="#000000" face="League Gothic">Live Support erhalten<\/font>/<!-- Mikogo Session Login Start -->\n<!-- <form method="POST" action="http:\/\/go.mikogo.com" style="display: inline;"> -->\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="975-218-294">\n <input type="hidden" name="sn" id="sn" value="i">\n <input type="submit" value="Live Demo beitreten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="2" checked="checked">\n <\/form>\n <form method="POST" action="http:\/\/go.mikogo.com" >\n <input type="hidden" name="sl" id="sl" value="de">\n <input type="hidden" name="css" id="css" value="">\n <input type="hidden" name="sid" id="sid" value="134-791-826">\n <input type="hidden" name="sn" id="sn" value="s">\n <input type="submit" value="Support erhalten" id="btnSubmit" name="btnSubmit">\n <input type="hidden"id="cm" name="cm" value="1" checked="checked">\n <\/form>\n	<!-- Mikogo Session Login End -->/' | \
	sed "s/Use a spacebar or arrow keys to navigate/zum Navigieren LEERTASTE oder Pfeiltasten/g" | \
	sed "s/${page}_files/support_files/g" | \
	cat > $filename

echo "<!-- processed -->" >> $filename
rm $tmpfilename
# Strut.io web bugs löschen
tag=strut.io
loeschen
exit 0
